/**
 * File:   ExitAction.java
 * Author: Gvennet
 */
package gui.actions;

import dht.network.Network;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * todo write javadoc
 */
public final class ExitAction extends AbstractAction
{

	private final JFrame frame;

	private final ScheduledThreadPoolExecutor executor;

	private final Network network;

	public ExitAction(JFrame frame, ScheduledThreadPoolExecutor executor, Network network)
	{
		super("Выход");
		putValue(SHORT_DESCRIPTION, "Выход");
		putValue(MNEMONIC_KEY, KeyEvent.VK_X);
		this.frame = frame;
		this.executor = executor;
		this.network = network;
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		network.stopReceiving();
		executor.shutdownNow();
		frame.dispose();
	}
}
